const path = require('path');
const webpack = require('webpack');

// Plugins
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const Merge = require('webpack-merge');
const CommonConfig = require('./webpack.common.js');

const package = require('../package.json');

module.exports = Merge(CommonConfig, {
    output: {
        filename: 'js/[name].[hash].js',
        chunkFilename: 'js/[name].chunk.[hash].js'
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('production'),
            'aphf.VERSION': JSON.stringify(package.version),
            'aphf.cfg.API_ADDR': JSON.stringify('https://api.aphf2018.cn/aphf/v1'),
            'aphf.cfg.ADMIN_API_ADDR': JSON.stringify('https://admin.aphf2018.cn/api/aphf/v1'),
            'aphf.img.ADDR': JSON.stringify('https://files.aphf2018.cn/images/'),
            'aphf.file.ADDR': JSON.stringify('https://files.aphf2018.cn/files/')
        }),
        new CleanWebpackPlugin(['dist/web'], {
            root: path.resolve('./'),
            verbose: false
        }),
        new UglifyJSPlugin()
    ],
    resolve: {
        alias: {
            'vue': 'vue/dist/vue.esm',
        }
    }
});